package com.example.lenovo.musicplayer;

import android.app.Service;
import android.content.Intent;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Binder;
import android.os.IBinder;

import java.io.IOException;


/**
 * Created by Lenovo on 2017/10/21.
 */

public class MusicPlayerService extends Service {

    private MediaPlayer player;
    @Override
    public IBinder onBind(Intent intent) {
        return new MyBinder();
    }
    public class MyBinder extends Binder{
        public void playPause(){
            if(isPlaying()) {
                player.start();
            } else {
                player.pause();
            }
        }
        public boolean isPlaying() {
            return player.isPlaying();
        }
    }

    @Override
    public void onCreate() {
        super.onCreate();
        player = new MediaPlayer();

        try {
            player.setDataSource(this, Uri.parse(path));
            player.prepare();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
